n = int(input())
nums = [int(x) for x in input().split(" ")]
pre = 0
maxAns = nums[0]
for x in nums:
    pre = max(pre + x, x)
    maxAns = max(maxAns, pre)
print(maxAns)